import math
import itertools

def distance(city1, city2):
    """计算两个城市之间的距离"""
    return math.sqrt((city1[0] - city2[0])**2 + (city1[1] - city2[1])**2)

def traveling_salesman(cities):
    n = len(cities)
    all_sets = range(1, n)
    memo = {}

    def tsp(mask, pos):
        """
        mask: 已访问的城市集合（用二进制表示）
        pos: 当前所在的城市
        """
        if (mask, pos) in memo:
            return memo[(mask, pos)]

        if mask == (1 << n) - 1:  # 所有城市都已访问
            return distance(cities[pos], cities[0])

        min_dist = float('inf')
        for city in all_sets:
            if (1 << city) & mask == 0:  # 未访问的城市
                new_dist = distance(cities[pos], cities[city]) + tsp(mask | (1 << city), city)
                min_dist = min(min_dist, new_dist)

        memo[(mask, pos)] = min_dist
        return min_dist

    return tsp(1, 0)  # 从城市 0 出发，初始只访问了城市 0

# 示例用法
cities = [(0, 0), (1, 2), (3, 1), (5, 3), (2, 5)]
min_distance = traveling_salesman(cities)
print("最小旅行距离:", min_distance)